﻿Public Class FormMain
    Dim objUser As New clsUser
    Private Sub FormMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.WindowState = FormWindowState.Maximized
        connectDB()
        getUserListByCJ()
    End Sub

    Private Sub connectDB()
        g_szInitFileName = My.Application.Info.DirectoryPath & "\yf.ini"
        g_Server.szDrive = GetIniFile("SERVER", "DRIVE", "PostgreSQL ANSI", g_szInitFileName)
        g_Server.szIPadr = GetIniFile("SERVER", "IP", "", g_szInitFileName)
        g_Server.szDbn = GetIniFile("SERVER", "DBN", "ZHENANSF", g_szInitFileName)
        g_Server.szUid = GetIniFile("SERVER", "UID", "sa", g_szInitFileName)
        g_Server.szPas = GetIniFile("SERVER", "PAS", "sa", g_szInitFileName)
        g_Server.iOver = CInt(GetIniFile("SERVER", "OVER", "-1", g_szInitFileName))

        If False = g_fDBconnect And 0 = g_iDBconnResult Then
            If "" = g_Server.szIPadr Or "0.0.0.0" = g_Server.szIPadr Then
            Else
                g_fDBconnect = True

                'データベース接続
                With g_Server
                    g_iDBconnResult = DBacs.Connect(.szDrive, .szIPadr, .szDbn, .szUid, .szPas, .iOver)
                    If 1 <> g_iDBconnResult Then
                        .szDrive = CStr(IIf("PostgreSQL" = .szDrive, "PostgreSQL ANSI", "PostgreSQL"))
                        g_iDBconnResult = DBacs.Connect(.szDrive, .szIPadr, .szDbn, .szUid, .szPas, .iOver)
                    End If
                End With
            End If
        End If

    End Sub

    Private Sub getUserListByCJ()
        Dim dtUser As DataTable = objUser.getUserListByCJ(8)
        cmbOpers.Properties.Items.Clear()
        For index = 0 To dtUser.Rows.Count - 1
            cmbOpers.Properties.Items.Add(dtUser.Rows(index)("user_name"))
        Next
        If dtUser.Rows.Count > 0 Then
            cmbOpers.Properties.Items(0).CheckState = CheckState.Checked
        End If
        cmbOpers.Properties.DropDownRows = cmbOpers.Properties.Items.Count + 1
        cmbOpers.Properties.ShowButtons = False
        cmbOpers.Properties.ShowPopupCloseButton = False
    End Sub

    Private Sub btnJLCheckt_Click(sender As Object, e As EventArgs) Handles btnJLCheck.Click
        Dim formJLCheck As New FormJLCheck()
        formJLCheck.usr = cmbOpers.EditValue.ToString()
        formJLCheck.ShowDialog(Me)
    End Sub

    Private Sub btnJLCheckRecord_Click(sender As Object, e As EventArgs) Handles btnJLCheckRecord.Click
        Dim formJLCheckRecord As New FormJLCheckRecord()
        formJLCheckRecord.usr = cmbOpers.EditValue.ToString()
        formJLCheckRecord.ShowDialog(Me)
    End Sub

    Private Sub btnJPCheck_Click(sender As Object, e As EventArgs) Handles btnJPCheck.Click
        Dim formJPCheck As New FormJPCheck()
        formJPCheck.usr = cmbOpers.EditValue.ToString()
        formJPCheck.ShowDialog(Me)
    End Sub

    Private Sub btnJPCheckRecord_Click(sender As Object, e As EventArgs) Handles btnJPCheckRecord.Click
        Dim formJPCheckRecord As New FormJPCheckRecord()
        formJPCheckRecord.usr = cmbOpers.EditValue.ToString()
        formJPCheckRecord.ShowDialog(Me)
    End Sub

    Private Sub FormMain_FormClosed(sender As Object, e As FormClosedEventArgs) Handles MyBase.FormClosed
        DBacs.Disconnect()
    End Sub

End Class
